package graph

import "fmt"

func CanVisitAllRooms(rooms [][]int) bool {

	queue := []int{0}
	roomCount := len(rooms)
	visit := make([]bool, roomCount)
	visit[0] = true
	visitCount := 1

	for len(queue) > 0 {
		n := len(queue)
		fmt.Println(queue)
		for i := 0; i < n; i++ {
			for _, v := range rooms[queue[0]] {
				if !visit[v] {
					visit[v] = true
					visitCount++
					queue = append(queue, v)
				}
			}
		}

		queue = queue[n:]
	}

	return visitCount == roomCount

}
